﻿#region Copyright (C) 2005-2007 Team MediaPortal

/* 
 *      Copyright (C) 2005-2007 Team MediaPortal
 *      http://www.team-mediaportal.com
 *
 *  This Program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *   
 *  This Program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with GNU Make; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
 *  http://www.gnu.org/copyleft/gpl.html
 *
 */

#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using MediaPortal.GUI.Library;
using MediaPortal.Dialogs;
using MediaPortal.Configuration;
using MediaPortal.Util;

namespace HNBtecaj
{
    public class HNBTecaj : GUIWindow, ISetupForm
    {

        private static string f_tecaj = MediaPortal.Configuration.Config.GetFolder(MediaPortal.Configuration.Config.Dir.Config) + @"\hnbtecaj.xml";

        int configPrikaz;
        int configZamjeniCZS;

        string datumxml;


        public HNBTecaj()
        {
        }


        #region ISetupForm Members

        // Returns the name of the plugin which is shown in the plugin menu
        public string PluginName()
        {
            return "HNB tecaj";
        }

        // Returns the description of the plugin is shown in the plugin menu
        public string Description()
        {
            return "HNB tecaj";
        }

        // Returns the author of the plugin which is shown in the plugin menu
        public string Author()
        {
            return "cane";
        }

        // show the setup dialog
        public void ShowPlugin()
        {
            //MessageBox.Show("Nothing to configure, this is just an example");
        }

        // Indicates whether plugin can be enabled/disabled
        public bool CanEnable()
        {
            return true;
        }

        // Get Windows-ID
        public int GetWindowId()
        {
            // WindowID of windowplugin belonging to this setup
            // enter your own unique code
            return 16580;
        }

        // Indicates if plugin is enabled by default;
        public bool DefaultEnabled()
        {
            return true;
        }

        // indicates if a plugin has it's own setup screen
        public bool HasSetup()
        {
            return false;
        }

        /// <summary>
        /// If the plugin should have it's own button on the main menu of Mediaportal then it
        /// should return true to this method, otherwise if it should not be on home
        /// it should return false
        /// </summary>
        /// <param name="strButtonText">text the button should have</param>
        /// <param name="strButtonImage">image for the button, or empty for default</param>
        /// <param name="strButtonImageFocus">image for the button, or empty for default</param>
        /// <param name="strPictureImage">subpicture for the button or empty for none</param>
        /// <returns>true : plugin needs it's own button on home
        /// false : plugin does not need it's own button on home</returns>

        public bool GetHome(out string strButtonText, out string strButtonImage,
          out string strButtonImageFocus, out string strPictureImage)
        {
            strButtonText = PluginName();
            strButtonImage = String.Empty;
            strButtonImageFocus = String.Empty;
            strPictureImage = String.Empty;
            return true;
        }

        // With GetID it will be an window-plugin / otherwise a process-plugin
        // Enter the id number here again
        public override int GetID
        {
            get
            {
                return 16580;
            }

            set
            {
            }
        }

        #endregion

        public override bool Init()
        {
            return Load(GUIGraphicsContext.Skin + @"\HNBTecaj.xml");
        }

        #region Actions
        public override void OnAction(MediaPortal.GUI.Library.Action action)
        {
            //if (GUIWindowManager.ActiveWindowEx == (int)GUIWindow.Window.WINDOW_DIALOG_MENU) return;

            switch (action.wID)
            {
                case MediaPortal.GUI.Library.Action.ActionType.ACTION_CONTEXT_MENU:
                    {
                        meni();
                    }
                    break;
                //case MediaPortal.GUI.Library.Action.ActionType.ACTION_PREVIOUS_MENU:


                    //break;
                default:
                    base.OnAction(action);
                    return; // no simon related action button was pressed -> base onAction was executed, stop here
            }

        }
        #endregion

        private void meni()
        {
            GUIDialogMenu dlgMenu = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
            if (dlgMenu != null)
            {
                dlgMenu.Reset();
                dlgMenu.SetHeading("Postavke - HNBTecaj");
                dlgMenu.Add("Prikaz");
                dlgMenu.Add("Zamjeni CZS");
                dlgMenu.Add("Snimi postavke");

                dlgMenu.DoModal(GetID);

                switch (dlgMenu.SelectedLabel)
                {
                    case 0:  //Prikaz
                        meniPrikaz();
                        break;
                    case 1:  //Zamjeni CZS
                        meniZamjeniCZS();;
                        break;
                    case 2:  //Snimi postavke
                        snimipostavke(); ;
                        break;
                }

            }

        }

        private void snimipostavke()
        {
            using (MediaPortal.Profile.Settings xmlWriter = new MediaPortal.Profile.Settings(MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Config, "MediaPortal.xml")))
            {
                xmlWriter.SetValue("HNBTecaj", "Prikaz", configPrikaz);
                xmlWriter.SetValue("HNBTecaj", "ZamjeniSlova", configZamjeniCZS);
            }


            GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
            dlg.SetHeading("HNBTecaj - postavke snimljene");

            if (configPrikaz == 0)
            {
                dlg.SetLine(1, "Prikaz: Kupovni, srednji, prodajni");
            }            

            if (configPrikaz == 1)
            {
                dlg.SetLine(1, "Prikaz: Srednji");
            }

            if (configZamjeniCZS == 0)
            {
                dlg.SetLine(2, "Zamjeni CZS: Nikad");
            }

            if (configZamjeniCZS == 1)
            {
                dlg.SetLine(2, "Zamjeni CZS: Uvijek");
            } 

            dlg.DoModal(GUIWindowManager.ActiveWindow);

        }

        private void meniPrikaz()
        {
            GUIDialogMenu dlgMenu = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
            if (dlgMenu != null)
            {
                dlgMenu.Reset();
                dlgMenu.SetHeading("Prikaz - HNBTecaj");
                dlgMenu.Add("Kupovni, srednji, prodajni");
                dlgMenu.Add("Srednji");

                dlgMenu.DoModal(GetID);

                switch (dlgMenu.SelectedLabel)
                {
                    case 0:  //Kupovni, srednji, prodajni
                        HideAll();
                        PrikaziSve();
                        configPrikaz = 0;
                        break;
                    case 1:  //Srednji
                        HideAll();
                        PrikaziSrednji();
                        configPrikaz = 1;
                        break;
                }

            }

        }

        private void meniZamjeniCZS()
        {
            GUIDialogMenu dlgMenu = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
            if (dlgMenu != null)
            {
                dlgMenu.Reset();
                dlgMenu.SetHeading("Zamjeni CZS - HNBTecaj");
                dlgMenu.Add("Nikad");
                dlgMenu.Add("Uvijek");

                dlgMenu.DoModal(GetID);

                switch (dlgMenu.SelectedLabel)
                {
                    case 0:  //Nikad
                        configZamjeniCZS = 0;
                        GUIControl.SetControlLabel(16580, 11, "Tečajna lista, " + datumxml);
                        break;
                    case 1:  //Uvijek
                        configZamjeniCZS = 1;
                        GUIControl.SetControlLabel(16580, 11, "Tecajna lista, " + datumxml);
                        break;
                }

            }

        }


        protected override void OnPageLoad()
        {
            using (MediaPortal.Profile.Settings xmlReader = new MediaPortal.Profile.Settings(MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Config, "MediaPortal.xml")))
            {
                configPrikaz = xmlReader.GetValueAsInt("HNBTecaj", "Prikaz", 0);
                configZamjeniCZS = xmlReader.GetValueAsInt("HNBTecaj", "ZamjeniSlova", 0);
            }
            
            bool dlRes = false;
            dlRes = Download("http://www.pbz.hr/Tecajnice/Danasnja/HNBteclist.xml", f_tecaj);
            if (dlRes == true)
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(f_tecaj);

                XmlNodeList banka = xDoc.GetElementsByTagName("Bank");
                XmlNodeList datum = xDoc.GetElementsByTagName("Date");
                XmlNodeList ime = xDoc.GetElementsByTagName("Name");
                XmlNodeList kol = xDoc.GetElementsByTagName("Unit");
                XmlNodeList kupovni = xDoc.GetElementsByTagName("BuyRateForeign");
                XmlNodeList srednji = xDoc.GetElementsByTagName("MeanRate");
                XmlNodeList prodajni = xDoc.GetElementsByTagName("SellRateForeign");

                GUIControl.SetControlLabel(16580, 10, banka[0].InnerText);

                datumxml = datum[0].InnerText;

                if (configZamjeniCZS == 0)
                {
                    GUIControl.SetControlLabel(16580, 11, "Tečajna lista, " + datumxml);
                }

                if (configZamjeniCZS == 1)
                {
                    GUIControl.SetControlLabel(16580, 11, "Tecajna lista, " + datumxml);
                } 

                

                
                //EU
                GUIControl.SetControlLabel(16580, 20, ime[11].InnerText + "  " + kol[11].InnerText + "  " + string.Format("{0:F2}", Convert.ToDouble(srednji[11].InnerText)));
                GUIControl.SetControlLabel(16580, 50, ime[11].InnerText + "  " + kol[11].InnerText);
                GUIControl.SetControlLabel(16580, 51, string.Format("{0:F3}", Convert.ToDouble(kupovni[11].InnerText)));
                GUIControl.SetControlLabel(16580, 52, string.Format("{0:F3}", Convert.ToDouble(srednji[11].InnerText)));
                GUIControl.SetControlLabel(16580, 53, string.Format("{0:F3}", Convert.ToDouble(prodajni[11].InnerText)));


                //Australija
                GUIControl.SetControlLabel(16580, 22, ime[0].InnerText + "  " + kol[0].InnerText + "  " + string.Format("{0:F2}", Convert.ToDouble(srednji[0].InnerText)));
                GUIControl.SetControlLabel(16580, 55, ime[0].InnerText + "  " + kol[0].InnerText);
                GUIControl.SetControlLabel(16580, 56, string.Format("{0:F3}", Convert.ToDouble(kupovni[0].InnerText)));
                GUIControl.SetControlLabel(16580, 57, string.Format("{0:F3}", Convert.ToDouble(srednji[0].InnerText)));
                GUIControl.SetControlLabel(16580, 58, string.Format("{0:F3}", Convert.ToDouble(prodajni[0].InnerText)));

                //Kanada
                GUIControl.SetControlLabel(16580, 24, ime[1].InnerText + "  " + kol[1].InnerText + "  " + string.Format("{0:F2}", Convert.ToDouble(srednji[1].InnerText)));
                GUIControl.SetControlLabel(16580, 60, ime[1].InnerText + "  " + kol[1].InnerText);
                GUIControl.SetControlLabel(16580, 61, string.Format("{0:F3}", Convert.ToDouble(kupovni[1].InnerText)));
                GUIControl.SetControlLabel(16580, 62, string.Format("{0:F3}", Convert.ToDouble(srednji[1].InnerText)));
                GUIControl.SetControlLabel(16580, 63, string.Format("{0:F3}", Convert.ToDouble(prodajni[1].InnerText)));

                //Ceska
                GUIControl.SetControlLabel(16580, 26, ime[2].InnerText + "  " + kol[2].InnerText + "  " + string.Format("{0:F2}", Convert.ToDouble(srednji[2].InnerText)));
                GUIControl.SetControlLabel(16580, 65, ime[2].InnerText + "  " + kol[2].InnerText);
                GUIControl.SetControlLabel(16580, 66, string.Format("{0:F3}", Convert.ToDouble(kupovni[2].InnerText)));
                GUIControl.SetControlLabel(16580, 67, string.Format("{0:F3}", Convert.ToDouble(srednji[2].InnerText)));
                GUIControl.SetControlLabel(16580, 68, string.Format("{0:F3}", Convert.ToDouble(prodajni[2].InnerText)));

                //Danska
                GUIControl.SetControlLabel(16580, 28, ime[3].InnerText + "  " + kol[3].InnerText + "  " + string.Format("{0:F2}", Convert.ToDouble(srednji[3].InnerText)));
                GUIControl.SetControlLabel(16580, 70, ime[3].InnerText + "  " + kol[3].InnerText);
                GUIControl.SetControlLabel(16580, 71, string.Format("{0:F3}", Convert.ToDouble(kupovni[3].InnerText)));
                GUIControl.SetControlLabel(16580, 72, string.Format("{0:F3}", Convert.ToDouble(srednji[3].InnerText)));
                GUIControl.SetControlLabel(16580, 73, string.Format("{0:F3}", Convert.ToDouble(prodajni[3].InnerText)));

                //Madzarska
                GUIControl.SetControlLabel(16580, 30, ime[4].InnerText + "  " + kol[4].InnerText + "  " + string.Format("{0:F2}", Convert.ToDouble(srednji[4].InnerText)));
                GUIControl.SetControlLabel(16580, 75, ime[4].InnerText + "  " + kol[4].InnerText);
                GUIControl.SetControlLabel(16580, 76, string.Format("{0:F3}", Convert.ToDouble(kupovni[4].InnerText)));
                GUIControl.SetControlLabel(16580, 77, string.Format("{0:F3}", Convert.ToDouble(srednji[4].InnerText)));
                GUIControl.SetControlLabel(16580, 78, string.Format("{0:F3}", Convert.ToDouble(prodajni[4].InnerText)));

                //Japan
                GUIControl.SetControlLabel(16580, 32, ime[5].InnerText + "  " + kol[5].InnerText + "  " + string.Format("{0:F2}", Convert.ToDouble(srednji[5].InnerText)));
                GUIControl.SetControlLabel(16580, 80, ime[5].InnerText + "  " + kol[5].InnerText);
                GUIControl.SetControlLabel(16580, 81, string.Format("{0:F3}", Convert.ToDouble(kupovni[5].InnerText)));
                GUIControl.SetControlLabel(16580, 82, string.Format("{0:F3}", Convert.ToDouble(srednji[5].InnerText)));
                GUIControl.SetControlLabel(16580, 83, string.Format("{0:F3}", Convert.ToDouble(prodajni[5].InnerText)));

                //Norveska
                GUIControl.SetControlLabel(16580, 34, ime[6].InnerText + "  " + kol[6].InnerText + "  " + string.Format("{0:F2}", Convert.ToDouble(srednji[6].InnerText)));
                GUIControl.SetControlLabel(16580, 85, ime[6].InnerText + "  " + kol[6].InnerText);
                GUIControl.SetControlLabel(16580, 86, string.Format("{0:F3}", Convert.ToDouble(kupovni[6].InnerText)));
                GUIControl.SetControlLabel(16580, 87, string.Format("{0:F3}", Convert.ToDouble(srednji[6].InnerText)));
                GUIControl.SetControlLabel(16580, 88, string.Format("{0:F3}", Convert.ToDouble(prodajni[6].InnerText)));

                //Svedska
                GUIControl.SetControlLabel(16580, 36, ime[7].InnerText + "  " + kol[7].InnerText + "  " + string.Format("{0:F2}", Convert.ToDouble(srednji[7].InnerText)));
                GUIControl.SetControlLabel(16580, 90, ime[7].InnerText + "  " + kol[7].InnerText);
                GUIControl.SetControlLabel(16580, 91, string.Format("{0:F3}", Convert.ToDouble(kupovni[7].InnerText)));
                GUIControl.SetControlLabel(16580, 92, string.Format("{0:F3}", Convert.ToDouble(srednji[7].InnerText)));
                GUIControl.SetControlLabel(16580, 93, string.Format("{0:F3}", Convert.ToDouble(prodajni[7].InnerText)));
                
                //Svicarska
                GUIControl.SetControlLabel(16580, 38, ime[8].InnerText + "  " + kol[8].InnerText + "  " + string.Format("{0:F2}", Convert.ToDouble(srednji[8].InnerText)));
                GUIControl.SetControlLabel(16580, 95, ime[8].InnerText + "  " + kol[8].InnerText);
                GUIControl.SetControlLabel(16580, 96, string.Format("{0:F3}", Convert.ToDouble(kupovni[8].InnerText)));
                GUIControl.SetControlLabel(16580, 97, string.Format("{0:F3}", Convert.ToDouble(srednji[8].InnerText)));
                GUIControl.SetControlLabel(16580, 98, string.Format("{0:F3}", Convert.ToDouble(prodajni[8].InnerText)));

                //Vel. Britanija
                GUIControl.SetControlLabel(16580, 40, ime[9].InnerText + "  " + kol[9].InnerText + "  " + string.Format("{0:F2}", Convert.ToDouble(srednji[9].InnerText)));
                GUIControl.SetControlLabel(16580, 100, ime[9].InnerText + "  " + kol[9].InnerText);
                GUIControl.SetControlLabel(16580, 101, string.Format("{0:F3}", Convert.ToDouble(kupovni[9].InnerText)));
                GUIControl.SetControlLabel(16580, 102, string.Format("{0:F3}", Convert.ToDouble(srednji[9].InnerText)));
                GUIControl.SetControlLabel(16580, 103, string.Format("{0:F3}", Convert.ToDouble(prodajni[9].InnerText)));

                //SAD
                GUIControl.SetControlLabel(16580, 42, ime[10].InnerText + "  " + kol[10].InnerText + "  " + string.Format("{0:F2}", Convert.ToDouble(srednji[10].InnerText)));
                GUIControl.SetControlLabel(16580, 105, ime[10].InnerText + "  " + kol[10].InnerText);
                GUIControl.SetControlLabel(16580, 106, string.Format("{0:F3}", Convert.ToDouble(kupovni[10].InnerText)));
                GUIControl.SetControlLabel(16580, 107, string.Format("{0:F3}", Convert.ToDouble(srednji[10].InnerText)));
                GUIControl.SetControlLabel(16580, 108, string.Format("{0:F3}", Convert.ToDouble(prodajni[10].InnerText)));

                //Poljska
                GUIControl.SetControlLabel(16580, 44, ime[12].InnerText + "  " + kol[12].InnerText + "  " + string.Format("{0:F2}", Convert.ToDouble(srednji[12].InnerText)));
                GUIControl.SetControlLabel(16580, 110, ime[12].InnerText + "  " + kol[12].InnerText);
                GUIControl.SetControlLabel(16580, 111, string.Format("{0:F3}", Convert.ToDouble(kupovni[12].InnerText)));
                GUIControl.SetControlLabel(16580, 112, string.Format("{0:F3}", Convert.ToDouble(srednji[12].InnerText)));
                GUIControl.SetControlLabel(16580, 113, string.Format("{0:F3}", Convert.ToDouble(prodajni[12].InnerText)));

                if (File.Exists(f_tecaj))
                {
                    File.Delete(f_tecaj);
                }

                if (configPrikaz == 0)
                {
                    PrikaziSve();
                }

                if (configPrikaz == 1)
                {
                    PrikaziSrednji();
                }

            }
        }

        private void PrikaziSrednji()
        {

            GUIControl.ShowControl(16580, 10);
            GUIControl.ShowControl(16580, 11);
            GUIControl.ShowControl(16580, 15);
            GUIControl.ShowControl(16580, 20);
            GUIControl.ShowControl(16580, 21);
            GUIControl.ShowControl(16580, 22);
            GUIControl.ShowControl(16580, 23);
            GUIControl.ShowControl(16580, 24);
            GUIControl.ShowControl(16580, 25);
            GUIControl.ShowControl(16580, 26);
            GUIControl.ShowControl(16580, 27);
            GUIControl.ShowControl(16580, 28);
            GUIControl.ShowControl(16580, 29);
            GUIControl.ShowControl(16580, 30);
            GUIControl.ShowControl(16580, 31);
            GUIControl.ShowControl(16580, 32);
            GUIControl.ShowControl(16580, 33);
            GUIControl.ShowControl(16580, 34);
            GUIControl.ShowControl(16580, 35);
            GUIControl.ShowControl(16580, 36);
            GUIControl.ShowControl(16580, 37);
            GUIControl.ShowControl(16580, 38);
            GUIControl.ShowControl(16580, 39);
            GUIControl.ShowControl(16580, 40);
            GUIControl.ShowControl(16580, 41);
            GUIControl.ShowControl(16580, 42);
            GUIControl.ShowControl(16580, 43);
            GUIControl.ShowControl(16580, 44);
            GUIControl.ShowControl(16580, 45);

        }


        private void PrikaziSve()
        {

            GUIControl.ShowControl(16580, 10);
            GUIControl.ShowControl(16580, 11);
            GUIControl.ShowControl(16580, 12);
            GUIControl.ShowControl(16580, 13);
            GUIControl.ShowControl(16580, 14);
            GUIControl.ShowControl(16580, 16);
            GUIControl.ShowControl(16580, 50);
            GUIControl.ShowControl(16580, 51);
            GUIControl.ShowControl(16580, 52);
            GUIControl.ShowControl(16580, 53);
            GUIControl.ShowControl(16580, 54);
            GUIControl.ShowControl(16580, 55);
            GUIControl.ShowControl(16580, 56);
            GUIControl.ShowControl(16580, 57);
            GUIControl.ShowControl(16580, 58);
            GUIControl.ShowControl(16580, 59);
            GUIControl.ShowControl(16580, 60);
            GUIControl.ShowControl(16580, 61);
            GUIControl.ShowControl(16580, 62);
            GUIControl.ShowControl(16580, 63);
            GUIControl.ShowControl(16580, 64);
            GUIControl.ShowControl(16580, 65);
            GUIControl.ShowControl(16580, 66);
            GUIControl.ShowControl(16580, 67);
            GUIControl.ShowControl(16580, 68);
            GUIControl.ShowControl(16580, 69);
            GUIControl.ShowControl(16580, 70);
            GUIControl.ShowControl(16580, 71);
            GUIControl.ShowControl(16580, 72);
            GUIControl.ShowControl(16580, 73);
            GUIControl.ShowControl(16580, 74);
            GUIControl.ShowControl(16580, 75);
            GUIControl.ShowControl(16580, 76);
            GUIControl.ShowControl(16580, 77);
            GUIControl.ShowControl(16580, 78);
            GUIControl.ShowControl(16580, 79);
            GUIControl.ShowControl(16580, 80);
            GUIControl.ShowControl(16580, 81);
            GUIControl.ShowControl(16580, 82);
            GUIControl.ShowControl(16580, 83);
            GUIControl.ShowControl(16580, 84);
            GUIControl.ShowControl(16580, 85);
            GUIControl.ShowControl(16580, 86);
            GUIControl.ShowControl(16580, 87);
            GUIControl.ShowControl(16580, 88);
            GUIControl.ShowControl(16580, 89);
            GUIControl.ShowControl(16580, 90);
            GUIControl.ShowControl(16580, 91);
            GUIControl.ShowControl(16580, 92);
            GUIControl.ShowControl(16580, 93);
            GUIControl.ShowControl(16580, 94);
            GUIControl.ShowControl(16580, 95);
            GUIControl.ShowControl(16580, 96);
            GUIControl.ShowControl(16580, 97);
            GUIControl.ShowControl(16580, 98);
            GUIControl.ShowControl(16580, 99);
            GUIControl.ShowControl(16580, 100);
            GUIControl.ShowControl(16580, 101);
            GUIControl.ShowControl(16580, 102);
            GUIControl.ShowControl(16580, 103);
            GUIControl.ShowControl(16580, 104);
            GUIControl.ShowControl(16580, 105);
            GUIControl.ShowControl(16580, 106);
            GUIControl.ShowControl(16580, 107);
            GUIControl.ShowControl(16580, 108);
            GUIControl.ShowControl(16580, 109);
            GUIControl.ShowControl(16580, 110);
            GUIControl.ShowControl(16580, 111);
            GUIControl.ShowControl(16580, 112);
            GUIControl.ShowControl(16580, 113);
            GUIControl.ShowControl(16580, 114);
        }

        private void HideAll()
        {
            GUIControl.HideControl(16580, 10);
            GUIControl.HideControl(16580, 11);
            GUIControl.HideControl(16580, 12);
            GUIControl.HideControl(16580, 13);
            GUIControl.HideControl(16580, 14);
            GUIControl.HideControl(16580, 15);
            GUIControl.HideControl(16580, 16);
            GUIControl.HideControl(16580, 20);
            GUIControl.HideControl(16580, 21);
            GUIControl.HideControl(16580, 22);
            GUIControl.HideControl(16580, 23);
            GUIControl.HideControl(16580, 24);
            GUIControl.HideControl(16580, 25);
            GUIControl.HideControl(16580, 26);
            GUIControl.HideControl(16580, 27);
            GUIControl.HideControl(16580, 28);
            GUIControl.HideControl(16580, 29);
            GUIControl.HideControl(16580, 30);
            GUIControl.HideControl(16580, 31);
            GUIControl.HideControl(16580, 32);
            GUIControl.HideControl(16580, 33);
            GUIControl.HideControl(16580, 34);
            GUIControl.HideControl(16580, 35);
            GUIControl.HideControl(16580, 36);
            GUIControl.HideControl(16580, 37);
            GUIControl.HideControl(16580, 38);
            GUIControl.HideControl(16580, 39);
            GUIControl.HideControl(16580, 40);
            GUIControl.HideControl(16580, 41);
            GUIControl.HideControl(16580, 42);
            GUIControl.HideControl(16580, 43);
            GUIControl.HideControl(16580, 44);
            GUIControl.HideControl(16580, 45);
            GUIControl.HideControl(16580, 50);
            GUIControl.HideControl(16580, 51);
            GUIControl.HideControl(16580, 52);
            GUIControl.HideControl(16580, 53);
            GUIControl.HideControl(16580, 54);
            GUIControl.HideControl(16580, 55);
            GUIControl.HideControl(16580, 56);
            GUIControl.HideControl(16580, 57);
            GUIControl.HideControl(16580, 58);
            GUIControl.HideControl(16580, 59);
            GUIControl.HideControl(16580, 60);
            GUIControl.HideControl(16580, 61);
            GUIControl.HideControl(16580, 62);
            GUIControl.HideControl(16580, 63);
            GUIControl.HideControl(16580, 64);
            GUIControl.HideControl(16580, 65);
            GUIControl.HideControl(16580, 66);
            GUIControl.HideControl(16580, 67);
            GUIControl.HideControl(16580, 68);
            GUIControl.HideControl(16580, 69);
            GUIControl.HideControl(16580, 70);
            GUIControl.HideControl(16580, 71);
            GUIControl.HideControl(16580, 72);
            GUIControl.HideControl(16580, 73);
            GUIControl.HideControl(16580, 74);
            GUIControl.HideControl(16580, 75);
            GUIControl.HideControl(16580, 76);
            GUIControl.HideControl(16580, 77);
            GUIControl.HideControl(16580, 78);
            GUIControl.HideControl(16580, 79);
            GUIControl.HideControl(16580, 80);
            GUIControl.HideControl(16580, 81);
            GUIControl.HideControl(16580, 82);
            GUIControl.HideControl(16580, 83);
            GUIControl.HideControl(16580, 84);
            GUIControl.HideControl(16580, 85);
            GUIControl.HideControl(16580, 86);
            GUIControl.HideControl(16580, 87);
            GUIControl.HideControl(16580, 88);
            GUIControl.HideControl(16580, 89);
            GUIControl.HideControl(16580, 90);
            GUIControl.HideControl(16580, 91);
            GUIControl.HideControl(16580, 92);
            GUIControl.HideControl(16580, 93);
            GUIControl.HideControl(16580, 94);
            GUIControl.HideControl(16580, 95);
            GUIControl.HideControl(16580, 96);
            GUIControl.HideControl(16580, 97);
            GUIControl.HideControl(16580, 98);
            GUIControl.HideControl(16580, 99);
            GUIControl.HideControl(16580, 100);
            GUIControl.HideControl(16580, 101);
            GUIControl.HideControl(16580, 102);
            GUIControl.HideControl(16580, 103);
            GUIControl.HideControl(16580, 104);
            GUIControl.HideControl(16580, 105);
            GUIControl.HideControl(16580, 106);
            GUIControl.HideControl(16580, 107);
            GUIControl.HideControl(16580, 108);
            GUIControl.HideControl(16580, 109);
            GUIControl.HideControl(16580, 110);
            GUIControl.HideControl(16580, 111);
            GUIControl.HideControl(16580, 112);
            GUIControl.HideControl(16580, 113);
            GUIControl.HideControl(16580, 114);
        }



        public static bool Download(string url, string fil)
        {
            int code = 0;

            if (!Win32API.IsConnectedToInternet(ref code))
            {
                return false;
            }
            using (WebClient client = new WebClient())
            {
                try
                {
                    client.Encoding = System.Text.Encoding.UTF8;
                    client.DownloadFile(url, fil);
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
        }
    }
}
